package com.iqiyi.pps.epg.core.utils;

import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by karkarrotxu on 2017/8/9.
 */
public final class ApiAlertPlatFormUtil {
    private static Logger logger = LoggerFactory.getLogger(ApiAlertPlatFormUtil.class);
    public static final int SEND_TYPE_CHAT = 1;
    public static final int SEND_TYPE_MAIL = 2;
    public static final int SEND_TYPE_MSG = 4;
    public static final int TOPIC_ID_LIVE_RECORD = 1167;
    public static final String SECRET_KEY_EPG = "0582beb0-7760-4887-937e-1e7ca7237fa1";
    public static final String PLATFORM_URL = "http://alert.qiyi.domain/event/create/";
    public static final String PARTITION_WARNNING_TYPE = "part_warnning";


    private ApiAlertPlatFormUtil() {
    }

    public static void doSend(int topic_id, String secret_key, String data, String users, int sendType) {
        int hotchat_enabled = ((sendType & SEND_TYPE_CHAT) == SEND_TYPE_CHAT) ? 1 : 0;
        int email_enabled = ((sendType & SEND_TYPE_MAIL) == SEND_TYPE_MAIL) ? 1 : 0;
        int sms_enabled = ((sendType & SEND_TYPE_MSG) == SEND_TYPE_MSG) ? 1 : 0;
        Map<String, Object> params = new HashMap<>();
        params.put("topic_id", topic_id);
        params.put("secret_key", secret_key);
        params.put("data", data);
        params.put("sms_enabled", sms_enabled);
        params.put("email_enabled", email_enabled);
        params.put("hotchat_enabled", hotchat_enabled);
        params.put("users", users);
        String retValue = ApiHttpRequestUtil.originalPost(PLATFORM_URL, params,null);
        logger.info(params +"|"+ retValue );
    }

    public static void main(String[] args){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("content","报警测试ERRor");
        doSend(TOPIC_ID_LIVE_RECORD,SECRET_KEY_EPG,jsonObject.toJSONString(),"yanchao_sx",SEND_TYPE_CHAT);
        String retValue = ApiHttpRequestUtil.doGet("http://xinqi.if.iqiyi.com/basic/categories.json?father_id=0",null,null);
        logger.info("retValue");
    }
}
